<!--业务审批modal-->
<template>
    <c-modal
            :width="width"
            :visible="visible"
            :title="title"
            :top="20"
            :bottom="20"
            @cancel="cancel"
    >
        <Spin size="large" fix v-if="Loading"></Spin>
        <Tabs v-model="tabName" id="Tab">
            <Tab-pane label="任务处理" name="name1">
                <div class="overflowContent" :key="key">
                    <application-view ref="application"/>
                    <div id="inforDiv" :key="key">
                        <Divider orientation="left">审批意见</Divider>
                        <handle ref="handle"/>
                    </div>
                </div>
                <div id="examinationButtonDiv">
                    <template v-for="item in buttonList">
                        <Button type="primary" style="margin-left: 20px" :value="item"
                                :key="item.status"  :loading="btnLoading"
                                @click="operation(item)">
                            {{item.name}}
                        </Button>
                    </template>
                </div>
            </Tab-pane>
            <Tab-pane label="审批意见" name="name2">
                <div class="overflowContent" :key="key">
                    <opinions ref="opinions"/>
                </div>
            </Tab-pane>
            <Tab-pane label="流程图" name="name3">
                <div class="overflowContent" :key="key">
                    <application-image ref="img"/>
                </div>
            </Tab-pane>
        </Tabs>
        <div slot="footer">
        </div>
    </c-modal>
</template>

<script>
    import applicationView from './application_view';
    import handle from './modules/process_handle'
    import applicationImage from '../db_application_approve/applicationImage'
    import {postAction} from '@/api/request'
    import opinions from '../db_application_approve/applicationOpinions'

    export default {
        name: "application-modal",
        components: {
            applicationView,
            handle,
            applicationImage,
            opinions
        },
        data() {
            return {
                tabName: "name1",
                scrollable: true,
                title: "审批详情",
                visible: false,
                disableSubmit: false,
                width: 800,
                height: 400,
                model: {},
                familyInfo: {},
                ss12007Id: "",
                buttonList: [],
                key: "",
                Loading: false,
                btnLoading:false,
            }
        },

        methods: {
            cancel() {
                this.visible = false;
            },
            edit(record) {
                this.ss12007Id = record.ss12001Id;
                this.tabName = "name1";
                this.visible = true;
                this.familyInfo = record;
                this.processstage = record.processstage;
                record.ss12007Id = record.ss12001Id;
                this.getApproveBtnMapList(record.processinstid, record.ss12007Id);
                //获取审批按钮信息
                this.$nextTick(() => {
                    this.$refs.application.edit(record);
                    this.$refs.img.edit(record, this.key);
                    this.$refs.opinions.edit(record);
                });
            },
            getApproveBtnMapList(processinstid, ss12007Id) {
                postAction("/api/ac/subsistence/ss00000Service/getApproveBtnMapList", {
                    processinstid: processinstid,
                    ss12007Id: ss12007Id
                }).then((res) => {
                    if (res.data.errcode == 0) {
                        this.buttonList = JSON.parse(JSON.stringify(res.data.data));
                    }
                })
            },
            operation(e) {
                let btnName = e.name;
                var infor = this.$refs.handle.check();
                if (infor) {
                    if (btnName.search("非救助") == -1 && btnName.search("终止")) {
                        this.check(infor, e);
                    } else {
                        this.buzTaskComplete(infor, e);
                    }
                }
            },
            check(infor, e) {
                var ss11301Id = this.$refs.application.familyInfo.ss11301Id;
                let that = this;
                that.Loading = true;
                let url = "/api/ac/subsistence/ss11310Service/check";
                postAction(url, {
                    processPhase: this.processstage,
                  familyId: ss11301Id
                }).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                        that.Loading = false;
                    } else {
                        this.buzTaskComplete(infor, e);
                    }
                })
            },

            buzTaskComplete(infor, e) {
                e.acttaskid = this.familyInfo.acttaskid;
                e.ss12007Id = this.ss12007Id;
                e.processstage = this.familyInfo.processstage;
                e.opusername = infor.opusername;
                e.optime = infor.optime;
                e.opmemo = infor.opmemo;
                e.opaction = e.name;
                var that = this;
                that.Loading = true;
                that.btnLoading = true;
                postAction("/api/ac/subsistence/ss00000Service/createBuzTaskComplete", e).then((res) => {
                    if (res.data.errcode == 0) {
                        this.$emit('ok');
                        this.visible = false;
                    } else {
                        this.$Message.error(res.data.errmsg);
                    }
                }).finally(() => {
                    that.Loading = false;
                    that.btnLoading = false;
                });
            }
        }
    }
</script>

<style scoped>
    #Tab {
        height: 100%;
    }

    /deep/ .ivu-tabs-content {
        height: calc(100% - 50px);
        position: relative;
    }

    #inforDiv {
        width: 100%;
        position: relative;
        margin-top: 20px;
        min-height: 200px;
    }

    #examinationButtonDiv {
        position: absolute;
        bottom: 10px;
        width: 100%;
        text-align: center;
    }

    .overflowContent {
        position: absolute;
        width: 100%;
        overflow-y: auto;
        height: calc(100% - 60px);
    }

    /deep/ .ivu-modal-body {
        padding-top: 0px;
    }

    /deep/ .ivu-modal-footer {
        border-top: 0px;
        padding: 0px;
    }
</style>
